home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- main()
- {
- char* server_name;
- printf("Content-type: text/html\n\n");
-
- printf("<HTML>\n");
- printf("<HEAD><TITLE>CGI Script How-to: Test Script</TITLE></HEAD>\n");
- printf("<BODY>\n");
-
- printf("<H1>CGI Script How-to<BR>determine the server's name for self referencing URL's</H1>\n");
-
- server_name = getenv("SERVER_NAME");
-
- if (server_name != NULL)
- {
- char* server_port = getenv("SERVER_PORT");
- char url[256];
- strcpy(url, "http://");
- strcat(url, server_name);
- if (server_port != NULL && strcmp(server_port, "80") != 0)
- {
- strcat(url, ":");
- strcat(url, server_port);
- }
- strcat(url, "/");
- printf("<H2>You can go to the home page of this server with the URL:\n");
- printf("<A HREF=\"%s\">%s</A></H2>\n", url, url);
- }
- else
- {
- printf("<H2>Server cannot be determined</H2>\n");
- }
-
- printf("</BODY></HTML>\n");
- exit(0);
- }
-
- /*
- * end of testserv.c
- */
-